home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / clif.h < prev    next >
Encoding:
C/C++ Source or Header  |  2010-07-18  |  4.4 KB  |  122 lines

  1. /*
  2.     Copyright (c)  2000, 2003        Dmitry Butskoy
  3.                     <buc@citadel.stu.neva.ru>
  4.     License:  LGPL v2.1 or any later
  5.  
  6.     See COPYING.LIB for the status of this software.
  7. */
  8.  
  9. #ifndef _CLIF_H
  10. #define _CLIF_H
  11.  
  12.  
  13. typedef struct CLIF_option_struct CLIF_option;
  14. struct CLIF_option_struct {
  15.     const char *short_opt;
  16.     const char *long_opt;
  17.     const char *arg_name;
  18.     const char *help_string;
  19.     int (*function) (CLIF_option *optn, char *arg);
  20.     void *data;
  21.     int (*function_plus) (CLIF_option *optn, char *arg);
  22.     unsigned int flags;
  23. };
  24. #define CLIF_END_OPTION        { 0, 0, 0, 0, 0, 0, 0, 0 }
  25.  
  26. typedef struct CLIF_argument_struct CLIF_argument;
  27. struct CLIF_argument_struct {
  28.     const char *name;
  29.     const char *help_string;
  30.     int (*function) (CLIF_argument *argm, char *arg, int index);
  31.     void *data;
  32.     unsigned int flags;
  33. };
  34. #define CLIF_END_ARGUMENT   { 0, 0, 0, 0, 0 }
  35.  
  36. /*  Argument flag bits.  */
  37. #define CLIF_MORE    (0x01)    /*  null or several  */
  38. #define CLIF_STRICT    (0x02)    /*  arg must be present   */
  39. #define CLIF_ACC_PREV    (0x04)  /*  arg must be accompanied with previous  */
  40.  
  41.  
  42. /*  Option flag bits.  */
  43.  
  44. /*  affected only by per-option flags   */
  45. #define CLIF_EXTRA        (0x0001)  /*  don`t show in usage line   */
  46. #define CLIF_EXIT        (0x0002)  /*  exit after handler return   */
  47. #define CLIF_EXCL        (0x0004)  /*  at exclusive area  */
  48.  
  49. /*  affected by per-option flags and by common `parse_flags' argument
  50.   of CLIF_parse_cmdline(). In last case appropriate bits are translated
  51.   for all the options.
  52. */
  53. #define CLIF_MAY_JOIN_ARG    (0x0010)
  54. #define _CLIF_STRICT_JOIN_ARG    (0x0020)
  55. #define CLIF_JOIN_ARG        (CLIF_MAY_JOIN_ARG|_CLIF_STRICT_JOIN_ARG)
  56. #define CLIF_MAY_NOEQUAL    (0x0040)
  57. #define _CLIF_STRICT_NOEQUAL    (0x0080)
  58. #define CLIF_NOEQUAL        (CLIF_MAY_NOEQUAL|_CLIF_STRICT_NOEQUAL)
  59. #define CLIF_MAY_KEYWORD    (0x0100)
  60. #define _CLIF_STRICT_KEYWORD    (0x0200)
  61. #define CLIF_KEYWORD        (CLIF_MAY_KEYWORD|_CLIF_STRICT_KEYWORD)
  62. #define CLIF_MAY_ONEDASH    (0x0400)
  63. #define _CLIF_STRICT_ONEDASH    (0x0800)
  64. #define CLIF_ONEDASH        (CLIF_MAY_ONEDASH|_CLIF_STRICT_ONEDASH)
  65. #define CLIF_OPTARG        (0x1000)  /*  allow missing optarg   */
  66. #define CLIF_ABBREV        (0x2000)  /*  allow long opt abbreviation  */
  67. #define CLIF_SEVERAL        (0x4000)  /*  several args in one opt`s arg  */
  68.  
  69. /*  affected only by common `parse_flags' arg of CLIF_parse_cmdline() .  */
  70. #define CLIF_HELP_EMPTY        (0x10000) /*  print help on empty cmdline  */
  71. #define CLIF_POSIX        (0x20000) /*  follow POSIX standard  */
  72. #define CLIF_FIRST_GROUP    (0x40000) /*  first arg - options` group   */
  73. #define CLIF_STRICT_EXCL    (0x80000) /*  at least one exclusive  */
  74. #define CLIF_SILENT        (0x100000)    /*  no errors on stderr   */
  75.  
  76. #define CLIF_MIN_ABBREV    2    /*  a minimal match length in abbrev  */
  77.  
  78.  
  79. extern int CLIF_parse (int argc, char **argv, CLIF_option *option_list,
  80.                 CLIF_argument *arg_list, unsigned int parse_flags);
  81. /*  history compatibility...  */
  82. #define CLIF_parse_cmdline(ARGC,ARGV,OPTN,ARGS,FLAGS)    \
  83.         CLIF_parse (ARGC, ARGV, OPTN, ARGS, FLAGS)
  84.  
  85. extern void CLIF_print_options (const char *header,
  86.                     const CLIF_option *option_list);
  87. extern void CLIF_print_arguments (const char *header,
  88.                     const CLIF_argument *argument_list);
  89. extern void CLIF_print_usage (const char *header, const char *progname, 
  90.                     const CLIF_option *option_list,
  91.                     const CLIF_argument *argument_list);
  92.  
  93. extern int CLIF_current_help (void);
  94.  
  95. /*  Common useful option handlers.  */
  96. extern int CLIF_version_handler (CLIF_option *optn, char *arg);
  97. extern int CLIF_set_flag (CLIF_option *optn, char *arg);
  98. extern int CLIF_unset_flag (CLIF_option *optn, char *arg);
  99. extern int CLIF_set_string (CLIF_option *optn, char *arg);
  100. extern int CLIF_set_int (CLIF_option *optn, char *arg);
  101. extern int CLIF_set_uint (CLIF_option *optn, char *arg);
  102. extern int CLIF_set_double (CLIF_option *optn, char *arg);
  103. extern int CLIF_call_func (CLIF_option *optn, char *arg);
  104.  
  105. extern int CLIF_arg_string (CLIF_argument *argm, char *arg, int index);
  106. extern int CLIF_arg_int (CLIF_argument *argm, char *arg, int index);
  107. extern int CLIF_arg_uint (CLIF_argument *argm, char *arg, int index);
  108. extern int CLIF_arg_double (CLIF_argument *argm, char *arg, int index);
  109. extern int CLIF_arg_func (CLIF_argument *argm, char *arg, int index);
  110.  
  111.  
  112. /*  Some useful macros.  */
  113.  
  114. #define CLIF_HELP_OPTION    \
  115.     { 0, "help", 0, "Read this help and exit",    \
  116.         CLIF_call_func, CLIF_current_help, 0, CLIF_EXTRA | CLIF_EXIT }
  117. #define CLIF_VERSION_OPTION(STR)  \
  118.     { "V", "version", 0, "Print version info and exit",    \
  119.         CLIF_version_handler, STR, 0, CLIF_EXTRA | CLIF_EXIT }
  120.  
  121. #endif    /*  _CLIF_H   */
  122.